﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HR_Business;

namespace HR_Web.Controls
{
    public partial class uclCompany : System.Web.UI.UserControl
    {
        public int SelectedItemId
        {
            get
            {
                return Convert.ToInt32(dropDownList.SelectedItem.Value);
            }

            set
            {
                ListItem item = dropDownList.Items.FindByValue(value.ToString());
                if (item != null)
                {
                    item.Selected = true;
                }
            }
        }

        public string SelectedtItemText
        {
            get
            {
                return dropDownList.SelectedItem.Text;
            }

            set
            {
                ListItem item = dropDownList.Items.FindByText(value);
                if (item != null)
                {
                    item.Selected = true;
                }
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        public void LoadData()
        {
            dropDownList.DataTextField = "Title";
            dropDownList.DataValueField = "Id";
            dropDownList.DataSource = new Company().GetAllCompanies();
            dropDownList.DataBind();
        }
    }
}